﻿@model Framework.Mvc.Util.EasyUIEditModel
@{    
    Layout = null;
}
<table id="@Model.GridID" class="easyui-datagrid" data-options="striped:true,rownumbers:true,pagination:true,singleSelect:true,collapsible:true,url:'@Model.GridJsonUrl',fitColumns:true,toolbar: '#@Model.ToolbarID'">
     @Html.Action("GridHead")
</table>

<div id="@Model.ToolbarID" class="easyui-toolbar" style="height:auto;padding:10px">  
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="@(Model.ControllerName)Add()">添加</a>  
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="@(Model.ControllerName)Edit()">编辑</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="@(Model.ControllerName)Remove()">删除</a>  
</div> 

<div id="@Model.WindowEditID" class="easyui-window" inline="true" closed="true" style="width: @(Model.WindowWidth)px; height: @(Model.WindowHeight)px; padding: 10px">
    <form id="@Model.FormEditID" action="@(Url.Action("edit"))" method="post">  
        @Html.Action("Detail") 
    </form>  
    <div style="margin-top:20px; text-align:center;">
        <a class="easyui-linkbutton" href="javascript:void(0)" onclick="$('#@(Model.FormEditID)').submit();">提交</a> 
        <a class="easyui-linkbutton" href="javascript:void(0)" onclick="$('#@(Model.WindowEditID)').window('close');">取消</a>
    </div>
</div>

<script type="text/javascript">
    //onload ------------------
    $(function () {
        $('#@(Model.FormEditID)').form({
            onSubmit: function () {
                @RenderSection("OnSubmit", false)
            },
            success: function (data) {
                var json = eval('(' + data + ')');
                $.messager.alert('Info', json.message);
                if(json.code > 0){
                    $("#@(Model.GridID)").datagrid("reload");
                    $('#@(Model.WindowEditID)').window('close');
                }
            }
        });
    });
    //remove --------------------------
    function @(Model.ControllerName)Remove() {
        var row = $('#@Model.GridID').datagrid('getSelected');  
        if (row) {
            $.post("@(Url.Action("delete"))", row, function (data) { 
                $.messager.alert('Info', data.message);
                if (data.code > 0) {
                    $("#@(Model.GridID)").datagrid("reload");
                }
            });
        } else {
            $.messager.alert('Info', '请选择具体的数据项');
        }
    }
    //edit ------------
    function @(Model.ControllerName)Edit() {
        var row = $('#@Model.GridID').datagrid('getSelected');  
        if (row) {
            $('#@(Model.WindowEditID)').window('open');
            $.post("@(Url.Action("DetailJson"))", row , function(data) {
                $('#@(Model.FormEditID)').form('load', data);
                @RenderSection("FormLoad", false)
            }, "json");
        } else {
            $.messager.alert('Info', '请选择具体的数据项');
        }
    }
    //add ------------------
    function @(Model.ControllerName)Add() {
        $('#@(Model.FormEditID)').form('clear');
        $('#@(Model.WindowEditID)').window('open');
    }
</script>
